<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Cron expressions | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'cron-expressions.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/cron-expressions.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/cron-expressions.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/cron-expressions.html" rel="nofollow" target="_blank">../en/cron-expressions.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="api-conventions.html">API conventions</a></span>
»
<span class="breadcrumb-node">Cron expressions</span>
</div>
<div class="navheader">
<span class="prev">
<a href="date-math-index-names.html">« Date math support in index names</a>
</span>
<span class="next">
<a href="common-options.html">Common options »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="cron-expressions"></a>Cron expressions<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rest-api/cron-expressions.asciidoc">edit</a>
</h2>
</div></div></div>
<p>A cron expression is a string of the following form:</p>
<div class="pre_wrapper lang-txt">
<pre class="programlisting prettyprint lang-txt">    &lt;seconds&gt; &lt;minutes&gt; &lt;hours&gt; &lt;day_of_month&gt; &lt;month&gt; &lt;day_of_week&gt; [year]</pre>
</div>
<p>Elasticsearch uses the cron parser from the <a href="http://www.quartz-scheduler.org" class="ulink" target="_top">Quartz Job Scheduler</a>.
For more information about writing Quartz cron expressions, see the
<a href="http://www.quartz-scheduler.org/documentation/quartz-2.2.x/tutorials/tutorial-lesson-06.html" class="ulink" target="_top">Quartz CronTrigger Tutorial</a>.</p>
<p>All schedule times are in coordinated universal time (UTC); other timezones are not supported.</p>
<div class="tip admon">
<div class="icon"></div>
<div class="admon_content">
<p>You can use the <a class="xref" href="elasticsearch-croneval.html" title="elasticsearch-croneval"><em>elasticsearch-croneval</em></a> command line tool to validate your cron expressions.</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cron-elements"></a>Cron expression elements<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rest-api/cron-expressions.asciidoc">edit</a>
</h3>
</div></div></div>
<p>All elements are required except for <code class="literal">year</code>.
See <a class="xref" href="cron-expressions.html#cron-special-characters" title="Cron special characters">Cron special characters</a> for information about the allowed special characters.</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;seconds&gt;</code>
</span>
</dt>
<dd>
(Required)
Valid values: <code class="literal">0</code>-<code class="literal">59</code> and the special characters <code class="literal">,</code> <code class="literal">-</code> <code class="literal">*</code> <code class="literal">/</code>
</dd>
<dt>
<span class="term">
<code class="literal">&lt;minutes&gt;</code>
</span>
</dt>
<dd>
(Required)
Valid values: <code class="literal">0</code>-<code class="literal">59</code> and the special characters <code class="literal">,</code> <code class="literal">-</code> <code class="literal">*</code> <code class="literal">/</code>
</dd>
<dt>
<span class="term">
<code class="literal">&lt;hours&gt;</code>
</span>
</dt>
<dd>
(Required)
Valid values: <code class="literal">0</code>-<code class="literal">23</code> and the special characters <code class="literal">,</code> <code class="literal">-</code> <code class="literal">*</code> <code class="literal">/</code>
</dd>
<dt>
<span class="term">
<code class="literal">&lt;day_of_month&gt;</code>
</span>
</dt>
<dd>
(Required)
Valid values: <code class="literal">1</code>-<code class="literal">31</code> and the special characters <code class="literal">,</code> <code class="literal">-</code> <code class="literal">*</code> <code class="literal">/</code> <code class="literal">?</code> <code class="literal">L</code> <code class="literal">W</code>
</dd>
<dt>
<span class="term">
<code class="literal">&lt;month&gt;</code>
</span>
</dt>
<dd>
(Required)
Valid values: <code class="literal">1</code>-<code class="literal">12</code>, <code class="literal">JAN</code>-<code class="literal">DEC</code>, <code class="literal">jan</code>-<code class="literal">dec</code>, and the special characters <code class="literal">,</code> <code class="literal">-</code> <code class="literal">*</code> <code class="literal">/</code>
</dd>
<dt>
<span class="term">
<code class="literal">&lt;day_of_week&gt;</code>
</span>
</dt>
<dd>
(Required)
Valid values: <code class="literal">1</code>-<code class="literal">7</code>, <code class="literal">SUN</code>-<code class="literal">SAT</code>, <code class="literal">sun</code>-<code class="literal">sat</code>,  and the special characters <code class="literal">,</code> <code class="literal">-</code> <code class="literal">*</code> <code class="literal">/</code> <code class="literal">?</code> <code class="literal">L</code> <code class="literal">#</code>
</dd>
<dt>
<span class="term">
<code class="literal">&lt;year&gt;</code>
</span>
</dt>
<dd>
(Optional)
Valid values: <code class="literal">1970</code>-<code class="literal">2099</code> and the special characters <code class="literal">,</code> <code class="literal">-</code> <code class="literal">*</code> <code class="literal">/</code>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cron-special-characters"></a>Cron special characters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rest-api/cron-expressions.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">*</code>
</span>
</dt>
<dd>
Selects every possible value for a field. For
example, <code class="literal">*</code> in the <code class="literal">hours</code> field means "every hour".
</dd>
<dt>
<span class="term">
<code class="literal">?</code>
</span>
</dt>
<dd>
No specific value. Use when you don’t care what the value
is. For example, if you want the schedule to trigger on a
particular day of the month, but don’t care what day of
the week that happens to be, you can specify <code class="literal">?</code> in the
<code class="literal">day_of_week</code> field.
</dd>
<dt>
<span class="term">
<code class="literal">-</code>
</span>
</dt>
<dd>
A range of values (inclusive). Use to separate a minimum
and maximum value. For example, if you want the schedule
to trigger every hour between 9:00 a.m. and 5:00 p.m., you
could specify <code class="literal">9-17</code> in the <code class="literal">hours</code> field.
</dd>
<dt>
<span class="term">
<code class="literal">,</code>
</span>
</dt>
<dd>
Multiple values. Use to separate multiple values for a
field. For example, if you want the schedule to trigger
every Tuesday and Thursday, you could specify <code class="literal">TUE,THU</code>
in the <code class="literal">day_of_week</code> field.
</dd>
<dt>
<span class="term">
<code class="literal">/</code>
</span>
</dt>
<dd>
Increment. Use to separate values when specifying a time
increment. The first value represents the starting point,
and the second value represents the interval. For example,
if you want the schedule to trigger every 20 minutes
starting at the top of the hour, you could specify <code class="literal">0/20</code>
in the <code class="literal">minutes</code> field. Similarly, specifying <code class="literal">1/5</code> in
<code class="literal">day_of_month</code> field will trigger every 5 days starting on
the first day of the month.
</dd>
<dt>
<span class="term">
<code class="literal">L</code>
</span>
</dt>
<dd>
Last. Use in the <code class="literal">day_of_month</code> field to mean the last day
of the month—​day 31 for January, day 28 for February in
non-leap years, day 30 for April, and so on. Use alone in
the <code class="literal">day_of_week</code> field in place of <code class="literal">7</code> or <code class="literal">SAT</code>, or after
a particular day of the week to select the last day of that
type in the month. For example <code class="literal">6L</code> means the last Friday
of the month. You can specify <code class="literal">LW</code> in the <code class="literal">day_of_month</code>
field to specify the last weekday of the month. Avoid using
the <code class="literal">L</code> option when specifying lists or ranges of values,
as the results likely won’t be what you expect.
</dd>
<dt>
<span class="term">
<code class="literal">W</code>
</span>
</dt>
<dd>
Weekday. Use to specify the weekday (Monday-Friday) nearest
the given day. As an example, if you specify <code class="literal">15W</code> in the
<code class="literal">day_of_month</code> field and the 15th is a Saturday, the
schedule will trigger on the 14th. If the 15th is a Sunday,
the schedule will trigger on Monday the 16th. If the 15th
is a Tuesday, the schedule will trigger on Tuesday the 15th.
However if you specify <code class="literal">1W</code> as the value for <code class="literal">day_of_month</code>,
and the 1st is a Saturday, the schedule will trigger on
Monday the 3rd—​it won’t jump over the month boundary. You
can specify <code class="literal">LW</code> in the <code class="literal">day_of_month</code> field to specify the
last weekday of the month. You can only use the <code class="literal">W</code> option
when the <code class="literal">day_of_month</code> is a single day—​it is not valid
when specifying a range or list of days.
</dd>
<dt>
<span class="term">
<code class="literal">#</code>
</span>
</dt>
<dd>
Nth XXX day in a month. Use in the <code class="literal">day_of_week</code> field to
specify the nth XXX day of the month. For example, if you
specify <code class="literal">6#1</code>, the schedule will trigger on the first
Friday of the month. Note that if you specify <code class="literal">3#5</code> and
there are not 5 Tuesdays in a particular month, the
schedule won’t trigger that month.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cron-expression-examples"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rest-api/cron-expressions.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="cron-example-daily"></a>Setting daily triggers<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rest-api/cron-expressions.asciidoc">edit</a>
</h4>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">0 5 9 * * ?</code>
</span>
</dt>
<dd>
Trigger at 9:05 a.m. UTC every day.
</dd>
<dt>
<span class="term">
<code class="literal">0 5 9 * * ? 2020</code>
</span>
</dt>
<dd>
Trigger at 9:05 a.m. UTC every day during the year 2020.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="cron-example-range"></a>Restricting triggers to a range of days or times<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rest-api/cron-expressions.asciidoc">edit</a>
</h4>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">0 5 9 ? * MON-FRI</code>
</span>
</dt>
<dd>
Trigger at 9:05 a.m. UTC Monday through Friday.
</dd>
<dt>
<span class="term">
<code class="literal">0 0-5 9 * * ?</code>
</span>
</dt>
<dd>
Trigger every minute starting at 9:00 a.m. UTC and ending at 9:05 a.m. UTC every day.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="cron-example-interval"></a>Setting interval triggers<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rest-api/cron-expressions.asciidoc">edit</a>
</h4>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">0 0/15 9 * * ?</code>
</span>
</dt>
<dd>
Trigger every 15 minutes starting at 9:00 a.m. UTC and ending at 9:45 a.m. UTC every day.
</dd>
<dt>
<span class="term">
<code class="literal">0 5 9 1/3 * ?</code>
</span>
</dt>
<dd>
Trigger at 9:05 a.m. UTC every 3 days every month, starting on the first day of the month.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="cron-example-day"></a>Setting schedules that trigger on a particular day<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rest-api/cron-expressions.asciidoc">edit</a>
</h4>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">0 1 4 1 4 ?</code>
</span>
</dt>
<dd>
Trigger every April 1st at 4:01 a.m. UTC.
</dd>
<dt>
<span class="term">
<code class="literal">0 0,30 9 ? 4 WED</code>
</span>
</dt>
<dd>
Trigger at 9:00 a.m. UTC and at 9:30 a.m. UTC every Wednesday in the month of April.
</dd>
<dt>
<span class="term">
<code class="literal">0 5 9 15 * ?</code>
</span>
</dt>
<dd>
Trigger at 9:05 a.m. UTC on the 15th day of every month.
</dd>
<dt>
<span class="term">
<code class="literal">0 5 9 15W * ?</code>
</span>
</dt>
<dd>
Trigger at 9:05 a.m. UTC on the nearest weekday to the 15th of every month.
</dd>
<dt>
<span class="term">
<code class="literal">0 5 9 ? * 6#1</code>
</span>
</dt>
<dd>
Trigger at 9:05 a.m. UTC on the first Friday of every month.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="cron-example-last"></a>Setting triggers using last<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/rest-api/cron-expressions.asciidoc">edit</a>
</h4>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">0 5 9 L * ?</code>
</span>
</dt>
<dd>
Trigger at 9:05 a.m. UTC on the last day of every month.
</dd>
<dt>
<span class="term">
<code class="literal">0 5 9 ? * 2L</code>
</span>
</dt>
<dd>
Trigger at 9:05 a.m. UTC on the last Monday of every month.
</dd>
<dt>
<span class="term">
<code class="literal">0 5 9 LW * ?</code>
</span>
</dt>
<dd>
Trigger at 9:05 a.m. UTC on the last weekday of every month.
</dd>
</dl>
</div>
</div>

</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="date-math-index-names.html">« Date math support in index names</a>
</span>
<span class="next">
<a href="common-options.html">Common options »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>